package tbk.zsxmlv.demo;

import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.TbkItemGetRequest;
import com.taobao.api.request.TbkTpwdCreateRequest;
import com.taobao.api.request.WirelessShareTpwdCreateRequest;
import com.taobao.api.response.TbkItemGetResponse;
import com.taobao.api.response.TbkTpwdCreateResponse;
import com.taobao.api.response.WirelessShareTpwdCreateResponse;
import zsxmlv.taobao.tbk.TaobaoTpwd;
import zsxmlv.taobao.tbk.TaobaoTpwdImpl;

/**
 * @Author: ZSXM
 * @Description: 测试获取商品
 * @Company: QIDI
 * @Date: Create by 2018/8/22 18:32
 * @Version: 1.0
 * @Modify by:
 */
public class Demo1 {

    public static final String SERVER_URL = "https://eco.taobao.com/router/rest";

    public static final String APP_KEY = "24954914";

    public static final String APP_SECRET = "e50284092cbdc7073b5f87f8ecd4bc3d";

    public static void main(String[] args) throws ApiException {


//        TaobaoTpwd tpwd = new TaobaoTpwdImpl();
//        TbkTpwdCreateRequest req = new TbkTpwdCreateRequest();
//        req.setLogo("https://img.alicdn.com//tfscom//i1//3320710786//O1CN011Hg1l5UOiWgd0QA_!!3320710786.jpg");
//        req.setText("中华老字号-农夫三拳");
//        req.setUrl("https://detail.m.tmall.com/item.htm?id=574265674611&skuId=3922591851319");
//        String s = tpwd.tpwdCreate(req);
//        System.out.println(s);

//        TaobaoClient client = new DefaultTaobaoClient(SERVER_URL, APP_KEY, APP_SECRET);
//        TbkTpwdCreateRequest req = new TbkTpwdCreateRequest();
//        req.setUserId("123");
//        req.setText("长度大于5个字符");
//        req.setUrl("https://detail.m.tmall.com/item.htm?id=574265674611&skuId=3922591851319");
//        req.setLogo("https://uland.taobao.com/");
//        req.setExt("{}");
//        TbkTpwdCreateResponse rsp = client.execute(req);
//        System.out.println(rsp.getBody());

//        TaobaoClient client = new DefaultTaobaoClient(SERVER_URL, APP_KEY, APP_SECRET);
//        WirelessShareTpwdCreateRequest req = new WirelessShareTpwdCreateRequest();
//        WirelessShareTpwdCreateRequest.GenPwdIsvParamDto obj1 = new WirelessShareTpwdCreateRequest.GenPwdIsvParamDto();
////        obj1.setExt("{\"xx\":\"xx\"}");
//        obj1.setLogo("https://img.alicdn.com//tfscom//i1//3320710786//O1CN011Hg1l5UOiWgd0QA_!!3320710786.jpg");
//        obj1.setUrl("https://detail.m.tmall.com/item.htm?id=572626495725&ali_trackid=2:mm_52151605_46574702_1240804474:1534945334_210_505240620&spm=a2e2e.10720394/c.90100100.003&e=B52bkjtvYvpZ473kEgq_AyOkbcfWH1nsOJhV7TWcK4HFxHz2gy1bZfHI_ndYw2bUpOadKxsI4QH3csqvfaXCpfurJl3AHA3vHqN3CrDUeQafmCWj-y2GQkGW9Ph7XBU0vUO-dIJK55kuZo2bt7pZ0NXyukVXAdq-P2lhNJ3oLalb9DciA8WNiQPE1nwE7VzuSRwfol2SygCB2__K79m7TGwYuMfZk2qf1OL5Nwg-hH4jpG3H1h9Z7O2ip1jZYgI4AUNPX-01LjWJRsRq2_xVWmUzJ_g4ErC4Se6rUv-Tn9oDRb1Etzp3Lw&type=2&tk_cps_param=52151605&tkFlag=0");
//        obj1.setText("霞姐,我来给你分享购物券来了");
////        obj1.setUserId(24234234234L);
//        req.setTpwdParam(obj1);
//        WirelessShareTpwdCreateResponse rsp = client.execute(req);
//        System.out.println(rsp.getBody());

        TaobaoClient taobaoClient = new DefaultTaobaoClient(SERVER_URL, APP_KEY, APP_SECRET);

        TbkItemGetRequest request = new TbkItemGetRequest();

        // 需返回的字段列表
        request.setFields("num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url,seller_id,volume,nick");

        // 查询词
        request.setQ("女装");

        // 后台类目ID，用,分割，最大10个，该ID可以通过taobao.itemcats.get接口获取到 eg: 16,18
        // request.setCat("");

        // 所在地
        // request.setItemloc("");

        // 排序_des（降序），排序_asc（升序），销量（total_sales），淘客佣金比率（tk_rate）， 累计推广量（tk_total_sales），总支出佣金（tk_total_commi）
        request.setSort("tk_rate");

        // 是否商城商品，设置为true表示该商品是属于淘宝商城商品，设置为false或不设置表示不判断这个属性
        request.setIsTmall(true);

        TbkItemGetResponse execute = taobaoClient.execute(request);
        String body = execute.getBody();

        System.out.println(execute.getBody());

    }

}
